package org.eredlab.g4.demo.core;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.eredlab.g4.bmf.base.IReader;
import org.eredlab.g4.ccl.datastructure.Dto;
import org.eredlab.g4.ccl.datastructure.impl.BaseDto;

public class ReportHelper {
	
	/**
	 * 获取全部报表参数
	 */
	public static Dto[] getReportDtos(String type,IReader g4Reader,Dto inDto)
	{
		SimpleDateFormat df = new SimpleDateFormat("yyyy年M月");
		Dto[] result = new Dto[11];		
		result[0] = getWrappage(new String[]{type,df.format(new Date())});
		result[1] = getPurchasingFund(g4Reader,inDto);
		result[2] = getPurchasingModeAndManner(g4Reader,inDto);
		result[4] = new BaseDto();
		result[5] = new BaseDto();
		result[6] = new BaseDto();
		result[7] = new BaseDto();
		result[8] = new BaseDto();
		result[9] = new BaseDto();
		result[10] = new BaseDto();
		return result;
	}

	/**
	 * 获取封皮数据
	 * @return
	 */
	public static Dto getWrappage(String[] data)
	{
		Dto parametersDto = new BaseDto();
		parametersDto.put("sjqj", data[0]);
		parametersDto.put("bsrq", data[1]);
		return parametersDto;
	}

	/**
	 * 获取采购资金数据
	 * @return
	 */
	public static Dto getPurchasingFund(IReader g4Reader,Dto inDto)
	{
		Dto parametersDto = new BaseDto();
		List fieldsList1 = g4Reader.queryForList("PurchasingFund1",inDto);
		List fieldsList2 = g4Reader.queryForList("PurchasingFund2",inDto);
		List fieldsList3 = g4Reader.queryForList("PurchasingFund3",inDto);
		List fieldsList4 = g4Reader.queryForList("PurchasingFund4",inDto);		
		BaseDto r1 = (BaseDto)fieldsList1.get(0);
		BaseDto r2 = (BaseDto)fieldsList2.get(0);
		BaseDto r3 = (BaseDto)fieldsList3.get(0);
		BaseDto r4 = (BaseDto)fieldsList4.get(0);		
		for(int i = 0;i<11;i++)
		{				
			String temp1 = "zj" + 1 + (i + 1);			
			parametersDto.put(temp1, TenThousandFormat(r1.getAsString(temp1)));
			String temp2 = "zj" + 2 + (i + 1);			
			parametersDto.put(temp2, TenThousandFormat(r2.getAsString(temp2)));
			String temp3 = "zj" + 3 + (i + 1);			
			parametersDto.put(temp3, TenThousandFormat(r3.getAsString(temp3)));
			String temp4 = "zj" + 4 + (i + 1);			
			parametersDto.put(temp4, TenThousandFormat(r4.getAsString(temp4)));
		}
		parametersDto.put("zj110", r1.getAsString("zj110"));
		parametersDto.put("zj210", r1.getAsString("zj210"));
		parametersDto.put("zj310", r1.getAsString("zj310"));
		parametersDto.put("zj410", r1.getAsString("zj410"));
		return parametersDto;
	}
	
	/**
	 * 获取采购方式和组织形式
	 * @return
	 */
	public static Dto getPurchasingModeAndManner(IReader g4Reader,Dto inDto)
	{
		Dto parametersDto = new BaseDto();		
		String[][][] condition = {
									{{null,null,null},{"货物类",null,null},{"工程类","",""},{"服务类","",""}},
									{{null,"集中采购",""},{"货物类","集中采购",""},{"工程类","集中采购",""},{"服务类","集中采购",""}},
									{{null,"部门集中采购",""},{"货物类","部门集中采购",""},{"工程类","部门集中采购",""},{"服务类","部门集中采购",""}},
									{{null,"分散采购",""},{"货物类","分散采购",""},{"工程类","分散采购",""},{"服务类","分散采购",""}},
									{{null,null,""},{null,null,""},{null,null,""},{null,null,""}},
									{{null,null,""},{null,null,""},{null,null,""},{null,null,""}},
									{{null,null,""},{null,null,""},{null,null,""},{null,null,""}},
									{{null,null,""},{null,null,""},{null,null,""},{null,null,""}},
									{{null,null,""},{null,null,""},{null,null,""},{null,null,""}},
									{{null,null,null},{"货物类",null,null},{"工程类",null,null},{"服务类",null,null}},
									{{null,null,"公开招标"},{"货物类",null,"公开招标"},{"工程类",null,"公开招标"},{"服务类",null,"公开招标"}},
									{{null,null,"邀请招标"},{"货物类",null,"邀请招标"},{"工程类",null,"邀请招标"},{"服务类",null,"邀请招标"}},
									{{null,null,"邀请招标-由公开招标方式改变"},{null,null,"邀请招标-由公开招标方式改变"},{null,null,"邀请招标-由公开招标方式改变"},{null,null,"邀请招标-由公开招标方式改变"}},
									{{null,null,"竞争性谈判"},{null,null,"竞争性谈判"},{null,null,"竞争性谈判"},{null,null,"竞争性谈判"}},
									{{null,null,"竞争性谈判-由公开招标方式改变"},{null,null,"竞争性谈判-由公开招标方式改变"},{null,null,"竞争性谈判-由公开招标方式改变"},{null,null,"竞争性谈判-由公开招标方式改变"}},
									{{null,null,"单一来源"},{null,null,"单一来源"},{null,null,"单一来源"},{null,null,"单一来源"}},
									{{null,null,"单一来源-由公开招标方式改变"},{null,null,"单一来源-由公开招标方式改变"},{null,null,"单一来源-由公开招标方式改变"},{null,null,"单一来源-由公开招标方式改变"}},
									{{null,null,"询价"},{null,null,"询价"},{null,null,"询价"},{null,null,"询价"}},
									{{null,null,"询价-由公开招标方式改变"},{null,null,"询价-由公开招标方式改变"},{null,null,"询价-由公开招标方式改变"},{null,null,"询价-由公开招标方式改变"}}
								 };
		for(int i=0;i<19;i++)
		{									
			for(int j=0;j<4;j++)
			{
				Dto inDtoTemp = inDto;
				inDtoTemp.put("prd_name", condition[i][j][0]);
				inDtoTemp.put("pur_organizemode", condition[i][j][1]);
				inDtoTemp.put("purm_name", condition[i][j][2]);
				List fieldsList = g4Reader.queryForList("PurchasingModeAndManner",inDtoTemp);
				BaseDto r = (BaseDto)fieldsList.get(0);
				r.getAsString("");
				parametersDto.put("zzfs" + i + j, r.getAsString("zzfs"));
			}
		}		
		return parametersDto;
	}
	
	/**
	 * 获取采购主体数据
	 * @return
	 */
	public static Dto getPurchasingMainBody(IReader g4Reader,Dto inDto)
	{
		return null;
	}
	
	/**
	 * 获取政府采购合同授予情况
	 * @return
	 */
	public static Dto getPurchasingAward(IReader g4Reader,Dto inDto)
	{
		return null;
	}
	
	/**
	 * 获取专项统计表--节能
	 * @return
	 */
	public static Dto getEnergyConservation(IReader g4Reader,Dto inDto)
	{
		return null;
	}
	
	/**
	 * 获取专项统计--环保
	 * @return
	 */
	public static Dto getEnvironmentalProtection(IReader g4Reader,Dto inDto)
	{
		return null;
	}
	
	/**
	 * 获取专项统计--其他
	 * @return
	 */
	public static Dto getOther(IReader g4Reader,Dto inDto)
	{
		return null;
	}
	
	/**
	 * 格式化成万
	 * @return
	 */
	public static Double TenThousandFormat(String data)
	{
		DecimalFormat df  = new DecimalFormat("#.0000"); 
		Double result = new Double(0);
		try
		{
			result = new Double(df.format(data));
		}
		catch(Exception e)
		{
		}
		return result;
	}
}
